﻿using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ByteSite.Quartz
{

    [DisallowConcurrentExecution]
    public class NewIJob : IJob
    {
        private readonly static object _sync = new object();

        public virtual void Run(IJobExecutionContext context, ref string result)
        {

        }

        public Task Execute(IJobExecutionContext context)
        {
            lock (_sync)
            {
                string result = string.Empty;
                Entitys.QuartzTask task = context.GetTaskOptions();
                Run(context,ref result);
                
                Entitys.QuartzLog log = new Entitys.QuartzLog();
                log.task_id = task.id.ToString();
                log.add_time = DateTime.Now;
                log.result = result;
                log.title = task.name;
                new BLL.quartz_log().Add(log);


                return Task.FromResult(true);
            }
        }
    }
}
